//login.js
//获取应用实例
var app = getApp();
Page({
  data: {
    remind: '加载中',
    btnName: '立即体验',
    angle: 0,
    userInfo: {},
    errorMes:['拯救世界很累，允许我获取权限可是很轻松的哦','别这么小气嘛，允许一下，乖~','不允许的话，我可是会生气的哦，哼！']
  },

  goToIndex: function() {
    wx.switchTab({
      url: '/pages/index/index',
    });
  },
  bindGetUserInfo: function(e) {
    var that = this;
    if ("getUserInfo:ok" == e.detail.errMsg) {
      wx.switchTab({
        url: '/pages/index/index',
      });
    } else {
      wx.showModal({
        title: '提示',
        content: that.data.errorMes[Math.floor(Math.random() * 3)],
        success: function(res) {
          if (res.confirm) {
            console.log('用户点击确定')
          } else {
            console.log('用户点击取消')
          }

        }
      })

    }
  },
  getUserInfoFun:function(){
    var that = this;
    app.getUserInfo(function (userInfo) {

      that.setData({
        userInfo: userInfo
      })

      var i = 2;
      setInterval(function () {
        i--;
        that.setData({
          btnName: '立即体验(' + i + ')'
        })
        if (i == 0) {
          wx.switchTab({
            url: '/pages/index/index',
          });
        }
      }, 1000)
    })
  },
  onLoad: function() {


  },
  onShow: function() {
    var that = this
    this.getUserInfoFun.call(this);
  },
  onReady: function() {
    var _this = this;
    setTimeout(function() {
      _this.setData({
        remind: ''
      });
    }, 1000);
    wx.onAccelerometerChange(function(res) {
      var angle = -(res.x * 30).toFixed(1);
      if (angle > 14) {
        angle = 14;
      } else if (angle < -14) {
        angle = -14;
      }
      if (_this.data.angle !== angle) {
        _this.setData({
          angle: angle
        });
      }
    });
  },
});